package org.dark.fund.api.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

@Data
@Builder
public class FundRateRecently {

    private String fundCode;

    /**
     * 往前偏移量-单位日
     */
    private int offset;

    /**
     * 涨跌幅
     */
    private List<DateValuePair> rates;

    @Data
    @AllArgsConstructor
    public static class DateValuePair implements Comparable{

        private String date;

        private BigDecimal rate;

        public static DateValuePair of(String key, BigDecimal value) {
            return new DateValuePair(key, value);
        }
        @Override
        public int compareTo(Object o) {
            if (this == o) {
                return 0;
            }
            if (o instanceof BigDecimal) {
                return this.compareTo(o);
            }
            if (o instanceof Number) {
                return this.rate.compareTo(new BigDecimal(String.valueOf(o)));
            }
            return 0;
        }
    }
}
